<template>
  <div class="user-edit">
    <Modal
      :title="title"
      v-model="visible"
      width="850"
      :styles="{ 'border-radius': '15px' }"
      :mask-closable="type == '0'"
      scrollable="true"
      transfer
    >
      <div>
        <Form ref="form" :model="form" :rules="ruleValidate" label-width="150">
          <FormItem label="通知名称：" prop="title">
            <Input v-model="form.title" />
         </FormItem>
          <FormItem label="备注说明：" >
            <Input v-model="form.remark" />
         </FormItem>
          <FormItem label="跳转类型" prop="jumpType">
            <RadioGroup v-model="form.jumpType">
              <Radio :label="0">平台展示</Radio>
              <Radio :label="1">外部展示</Radio>
              <Radio :label="2">文字展示</Radio>

            </RadioGroup>
         </FormItem>
          <FormItem label="跳转地址" v-if="form.jumpType == 1" prop="link">
            <Input v-model="form.link" placeholder="请输入跳转地址" />
         </FormItem>
          <FormItem label="跳转参数:" v-if="form.jumpType == 0" prop="activityId">
            <div style="display: flex">
              <Select
                v-model="form.activityId"
                placeholder="选择活动"
                style="max-width: 150px; margin-left: 10px"
              >
                <Option value="0">暂无</Option>
              </Select>
            </div>
         </FormItem>
       </Form>
      </div>
      <div slot="footer">
        <Button
          type="primary"
          size="large"
          :loading="submitLoading"
          @click="submit"
          >保存</Button
        >
        <Button size="large" @click="visible = false">取消</Button>
      </div>
      <!-- <div class="drawer-footer br" v-show="type != '0'">
        <Button type="primary" :loading="submitLoading" @click="submit"
          >提交</Button
        >
        <Button @click="visible = false">取消</Button>
      </div> -->
    </Modal>
  </div>
</template>

<script>
import {
  scIntegralTypeUpdate,
  scNoticeAdd,
  getScIntegralTypegetAll,
} from "@/api/index";
export default {
  name: "integral-clean-addEdit",
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    formData: {
      type: Object,
    },
  },
  data() {
    return {
      integralList: [],
      visible: this.value,
      title: "",
      passColor: "",
      submitLoading: false,
      maxHeight: 510,
      cleanDayShow: 0,
      form: {
        jumpType:2
      },
      ruleValidate: {
        title: [{ required: true, message: "请输入名称", trigger: "blur" }],
        activityId: [
          {
            required: true,
            message: "请选择活动",
            trigger: "blur",
          },
        ],

        jumpType: [
          {
            required: true,
            message: "请选择跳转类型",
            trigger: "change",
              type: "number",
          },
        ],
      },
    };
  },
  watch: {
    visible(val) {
      if (!val) {
        this.$emit("on-submit", false);
      }
    },
  },
  methods: {
    gettypeall() {
      getScIntegralTypegetAll({}).then((res) => {
        console.log(res);
        if (res.success) {
          this.integralList = res.result;
        }
      });
    },
    submit() {
      console.log(this.form);
      this.$refs.form.validate((valid) => {
        if (valid) {
          console.log(this.form);
          if (this.form.id) {
            scIntegralTypeUpdate(this.form).then((res) => {
              if (res.success) {
                this.$Message.success("操作成功");
                this.$emit("on-submit", true);
                this.visible = false;
              }
            });
          } else {
            scNoticeAdd({
              ...this.form
            }).then((res) => {
              if (res.success) {
                this.$Message.success("操作成功");
                this.$emit("on-submit", true);
                this.visible = false;
              }
            });
          }
        }
      });
    },
  },

  mounted() {
    this.gettypeall();
    this.form = this.formData;
    if (this.form.id) {
      this.title = "更新通知";
    } else {
      this.title = "添加通知";
    }
  },
};
</script>

<style lang="less">
@import "@/styles/drawer-common.less";
.ivu-form-item-content {
  display: flex;
  .txt {
    width: 45px;
    &.ml {
      margin-left: 10px;
    }
  }
}
</style>

